//
//	File Name   :	TestApp.cpp
//	Description :	TestApp implementation file.
//	Author		:	William McVicar
//  Mail		:	mcvicar.william@gmail.com
//

//  Precompiled Header
#include "ProteinEngine.h"

//  Library Includes

//  Local Includes
#include "Camera.h"
#include "MeshNode.h"

//  This includes
#include "TestApp.h"

//	Macros

//  Static Variables

//  Static Function Prototypes

//  Implementation

using namespace Protein;

CTestApp::CTestApp()
{

}

CTestApp::~CTestApp()
{

}

bool CTestApp::Initialise()
{
	OutputDebugString( _T("Initialise\n") );
 
  Matrix4 proj = Matrix4::CameraPerspectiveProjection( 1.0f, 1000.0f, 640.0f, 0.0f, 0.0f, 480.0f );


  Protein::Camera* camera = new Protein::Camera();
  camera->viewport( Viewport(0.0f, 0.0f, 640, 480 ) );
  camera->translate( Vector3f( 0.0f, 50.0f, 100.0f ) );
  camera->projectionMatrix( proj );
  camera->setNearDistance( 1.0f );
  camera->setFarDistance( 1000.0f );

  renderer().activeCamera( camera );

  Protein::MeshNode* pMeshNode = new Protein::MeshNode( "ultron_model.fbx" );

	return BaseApplication::Initialise();
}

bool CTestApp::Shutdown()
{
	OutputDebugString( _T("Shutdown\n") );
	return BaseApplication::Shutdown();
}

void CTestApp::Update()
{
  Protein::Camera* camera = renderer().activeCamera();
  camera->translate( Vector3f::i * clock().GetTickF() );
}

#ifdef DX10
void CTestApp::updateDX10Specific()
{
	m_Gamepad.Poll();

	if( m_Gamepad.IsButtonDown( XINPUT_GAMEPAD_A ) )
	{
		byte BattLevl = m_Gamepad.GetBatteryLevel();
		PROTEIN_UNUSED( BattLevl );
		__asm{ nop }
	}

	if( m_Gamepad.IsButtonDown( XINPUT_GAMEPAD_B ) )
		OutputDebugString( _T("B") );

	if( m_Gamepad.IsButtonDown( XINPUT_GAMEPAD_X ) )
		OutputDebugString( _T("X") );

	if( m_Gamepad.IsButtonDown( XINPUT_GAMEPAD_Y ) )
		OutputDebugString( _T("Y") );

	if( m_Gamepad.IsButtonDown( XINPUT_GAMEPAD_START ) )
		OutputDebugString( _T("START") );

	if( m_Gamepad.IsButtonDown( XINPUT_GAMEPAD_BACK ) )
		OutputDebugString( _T("BACK") );

	if( m_Gamepad.IsButtonDown( XINPUT_GAMEPAD_LEFT_SHOULDER ) )
		OutputDebugString( _T("LEFT_SHOULDER") );

	if( m_Gamepad.IsButtonDown( XINPUT_GAMEPAD_RIGHT_SHOULDER ) )
		OutputDebugString( _T("RIGHT_SHOULDER") );

	if( m_Gamepad.IsButtonDown( XINPUT_GAMEPAD_DPAD_UP ) )
		OutputDebugString( _T("DPAD_UP") );

	if( m_Gamepad.IsButtonDown( XINPUT_GAMEPAD_DPAD_DOWN ) )
		OutputDebugString( _T("DPAD_DOWN") );

	if( m_Gamepad.IsButtonDown( XINPUT_GAMEPAD_DPAD_LEFT ) )
		OutputDebugString( _T("DPAD_LEFT") );

	if( m_Gamepad.IsButtonDown( XINPUT_GAMEPAD_DPAD_RIGHT ) )
		OutputDebugString( _T("DPAD_RIGHT") );
}
#endif